package com.stream.producter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author:wesley
 */
@RestController
@EnableBinding(value = ProductChannel.class)
public class ProducterProcessController {

    @Autowired
    private ProductChannel productChannel;


    @PostMapping(value = "/send/msg/{msg}")
    public String sendMqMessage(@PathVariable("msg") String msg){
        productChannel.outChannel().send(MessageBuilder.withPayload(msg).build());
        return "send msg :["+msg+"] OK...";
    }

    @StreamListener(value = ProductChannel.inputChannel)
    public void processFeedback(String msg){
        System.out.println("**********************");
        System.out.println("processFeedback received msg : "+msg);
        System.out.println("**********************");
    }


}
